﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Xml;

namespace LocalBaseSet
{
    public class TS_Win_Class
    {
        public static string _xml_SysSetting_Filename = AppDomain.CurrentDomain.BaseDirectory + "Config.xml";
        public static string _xml_SysSetting_CompanyName = "武汉铁路局襄阳机务段";
        public static string _EXP_Direct = @"C:\襄阳机务段导出文件\";
        public static string _Version = "V1.00.00.00";
        public static string _BuildTime = " 2017-11-01";
        public static string _AppName = "襄阳机务段检修现场作业管理系统";
        #region//--获取软件的授权信息--//
        /// <summary>
        /// 获取软件授权信息
        /// </summary>
        /// <returns>字符串</returns>
        public string GetCopyRight()
        {
            return ("本软件授权给" + GetCompanyName() + "使用，本软件由" + GetDevCompanyName() + "开发！<br/>CopyRight &#169; 2013 By <a href='mailto:Softye@263.net'><font color=666666>" + GetsysName() + "</font></a> ！ All Rights Reserved ！");
        }
        public string GetCompanyName()
        {
            return (_xml_SysSetting_CompanyName);
        }
        public string GetDevCompanyName()
        {
            return ("武汉铁盛机电科技有限公司");
        }
        public string GetsysName()
        {
            return ("机车整备图像无线实时传输系统");
        }
        public static string GetSQlConnStr()
        {
            return GetSQLConnString.GetSQLConnString.getSQLConnString().getConnnString();
        }
        //public static string GetSQlConnStr()
        //{
        //    return "Data Source=10.103.238.47;Initial Catalog=TS_Tech_AllInOne;password=Windows2008;Pooling=false;persist security info=True;user id=sa;workstation id=SERVER;packet size=4096";
        //}
        public static string GetJT6SQlConnStr()
        {
            return @"Data Source=10.105.238.23;Initial Catalog=JCZB;password=Windows2008;Pooling=false;persist security info=True;user id=softye;workstation id=SERVER;packet size=4096";
        }
        #endregion
        #region//--填充List Comb控件--//
        public static void FillListTypeAct(System.Windows.Forms.ComboBox cb, string strSQL)
        {
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = comm;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                cb.DisplayMember = "f_name";
                cb.ValueMember = "f_id";
                cb.DataSource = ds.Tables[0];
            }
            else
            {
                cb.DataSource = null;
                cb.Text = "";
            }
            ad.Dispose();
            comm.Dispose();
            conn.Dispose();
        }
        public static void cbobox(System.Windows.Forms.ComboBox cb, string strSQL)
        {
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = comm;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            cb.DisplayMember = "f_name";
            cb.ValueMember = "f_id";
            cb.DataSource = ds.Tables[0];
            ad.Dispose();
            comm.Dispose();
            conn.Dispose();
        }
        public static void FillListTypeAct(System.Windows.Forms.ComboBox cb, string strSQL, string strConn)
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = comm;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            cb.DisplayMember = "f_name";
            cb.ValueMember = "f_id";
            cb.DataSource = ds.Tables[0];
            ad.Dispose();
            comm.Dispose();
            conn.Dispose();
            ds.Dispose();
        }
        public static void FillListTypeAct(System.Windows.Forms.ListBox cb, string strSQL)
        {
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = comm;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            cb.DisplayMember = "f_name";
            cb.ValueMember = "f_id";
            cb.DataSource = ds.Tables[0];
            ad.Dispose();
            comm.Dispose();
            conn.Dispose();

        }
        public static void FillListTypeAct(System.Windows.Forms.ListBox cb, string strSQL, string strConn)
        {
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand comm = new SqlCommand(strSQL, conn);
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = comm;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            cb.DisplayMember = "f_name";
            cb.ValueMember = "f_id";
            cb.DataSource = ds.Tables[0];
            ad.Dispose();
            comm.Dispose();
            conn.Dispose();
        }
        #endregion
        #region //--填充FlowLayoutPanel--//
        public static void Fill_FLP_RadioBox(System.Windows.Forms.FlowLayoutPanel flp, string strsql, System.EventHandler EventFunc)
        {
            int iNum = 0;
            RadioButton[] boxList = new RadioButton[100];
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strsql, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                boxList[iNum] = new RadioButton();
                boxList[iNum].Text = read["f_name"].ToString();
                boxList[iNum].Tag = read["f_id"].ToString();
                boxList[iNum].TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                boxList[iNum].CheckedChanged += new System.EventHandler(EventFunc);
                flp.Controls.Add(boxList[iNum]);
                iNum++;
            }
            read.Close();
            read.Dispose();
            comm.Dispose();
            conn.Close();
            conn.Dispose();
        }
        public static void Fill_FLP_RadioBox(System.Windows.Forms.FlowLayoutPanel flp, string strsql)
        {
            int iNum = 0;
            RadioButton[] boxList = new RadioButton[100];
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strsql, conn);
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
                boxList[iNum] = new RadioButton();
                boxList[iNum].Text = read["f_name"].ToString();
                boxList[iNum].Tag = read["f_id"].ToString();
                boxList[iNum].TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                flp.Controls.Add(boxList[iNum]);
                iNum++;
            }
            read.Close();
            read.Dispose();
            comm.Dispose();
            conn.Close();
            conn.Dispose();
        }
        #endregion
        #region//--将结果值整理成字符串--//
        public static string MakeSQLResultToOneString(string strSql, string strField, string strSeparator)
        {
            string str="";
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSql, conn);
            SqlDataReader read = comm.ExecuteReader();
            int i = 0;
            while(read.Read())
            {
                if (i == 0)
                {
                }
                else
                {
                    str += strSeparator;
                }
                str += read[strField].ToString().Trim();
                i++;
            }
            conn.Close();
            return str;
        }
        #endregion
        #region//--执行SQL语句--//
        public static void MySqlCom(string strSql)
        {
            SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
            SqlCommand MyClassComm = new SqlCommand(strSql, MyClassConn);
            MyClassConn.Open();
            MyClassComm.ExecuteNonQuery();
            MyClassConn.Close();
            MyClassConn.Dispose();
        }
        public static void MySqlCom(string strSql,string strConn)
        {
            SqlConnection MyClassConn = new SqlConnection(strConn);
            SqlCommand MyClassComm = new SqlCommand(strSql, MyClassConn);
            MyClassConn.Open();
            MyClassComm.ExecuteNonQuery();
            MyClassConn.Close();
            MyClassConn.Dispose();
        }
        /// <summary>
        /// 自定义SQL命令执行语句--返回行号
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <returns>返回执行后行号</returns>
        public static string MySqlComGetID(string strSql)
        {
            SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
            strSql = strSql + ";select @@IDENTITY As 'Identity'";
            SqlCommand MyClassComm = new SqlCommand(strSql, MyClassConn);
            MyClassConn.Open();
            string Index = (MyClassComm.ExecuteScalar()).ToString().Trim();
            MyClassConn.Close();
            MyClassConn.Dispose();
            return Index;
        }
        public static string MySqlComGetID(string strSql, string strConn)
        {
            SqlConnection MyClassConn = new SqlConnection(strConn);
            strSql = strSql + ";select @@IDENTITY As 'Identity'";
            SqlCommand MyClassComm = new SqlCommand(strSql, MyClassConn);
            MyClassConn.Open();
            string Index = (MyClassComm.ExecuteScalar()).ToString().Trim();
            MyClassConn.Close();
            MyClassConn.Dispose();
            return Index;
        }
        public static string GetSQlFieldValue(string strSql, string Field,string strConn)
        {
            string str = "";
            SqlConnection conn = new SqlConnection(strConn);
            conn.Open();
            SqlCommand comm = new SqlCommand(strSql, conn);
            SqlDataReader read = comm.ExecuteReader();
            if (read.HasRows)
            {
                read.Read();
                str = read[Field].ToString().Trim();
            }
            else
            {
                str = null;
            }
            conn.Close();
            return str;
        }
        public static string GetSQlFieldValue(string strSql, string Field)
        {
            string str = "";
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSql, conn);
            SqlDataReader read = comm.ExecuteReader();
            if (read.HasRows)
            {
                read.Read();
                str = read[Field].ToString().Trim();
            }
            else
            {
                str = null;
            }
            conn.Close();
            return str;
        }
        public static string[] GetSQlFieldValue(string strSql, string[] Field)
        {
            string[] str = new string[Field.Length];
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSql, conn);
            SqlDataReader read = comm.ExecuteReader();
            if (read.HasRows)
            {
                read.Read();
                for (int i = 0; i < Field.Length; i++)
                {
                    str[i] = read[Field[i]].ToString().Trim();
                }
            }
            else
            {
                str[0] = "-1";
            }
            conn.Close();
            return str;
        }
        public static string GetSQlFieldValue_1(string strSql, string Field)
        {
            string str = "";
            SqlConnection conn = new SqlConnection(GetSQlConnStr());
            conn.Open();
            SqlCommand comm = new SqlCommand(strSql, conn);
            SqlDataReader read = comm.ExecuteReader();
            if (read.HasRows)
            {
                read.Read();
                str = read[Field].ToString().Trim();
            }
            else
            {
                str = "";
            }
            conn.Close();
            return str;
        }
        #endregion
        #region //--返回填充的数据集--//
        public static DataSet GetFilledDataSet(string strSQL)
        {
            DataSet dt = new DataSet();
            try
            {
                SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, MyClassConn);
                sda.Fill(dt);
                return dt;
            }
            catch
            {
                return dt;
            }
        }
        public static DataTable GetFilledDataTable(string strSQL)
        {
            DataTable dt = new DataTable();
            try
            {
                SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, MyClassConn);
                sda.Fill(dt);
                return dt;
            }
            catch
            {
                return dt;
            }
        }

        public static DataTable GetFilledDataTable_Server(string strSQL)
        {
            DataTable dt = new DataTable();
            try
            {
                SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, MyClassConn);
                sda.Fill(dt);
                return dt;
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public static void FilledDataTable(string strSQL, DataTable dt)
        {
            try
            {
                SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, MyClassConn);
                sda.Fill(dt);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public static void FilledDataTable_Server(string strSQL, DataTable dt)
        {
            try
            {
                SqlConnection MyClassConn = new SqlConnection(GetSQlConnStr());
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, MyClassConn);
                sda.Fill(dt);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public static DataTable GetFilledDataTable(string strSQL, SqlConnection conn)
        {
            DataTable dt = new DataTable();
            try
            {
                SqlDataAdapter sda = new SqlDataAdapter(strSQL, conn);
                sda.Fill(dt);
                return dt;
            }
            catch
            {
                return null;
            }
        }

        #endregion
        #region//--数据操作权限判定--//
        public static Boolean GetDataRankAuthority(string UserDataRank, string ObjectDataRank)
        {
            Boolean brhandle = false;
            try
            {
                if (Convert.ToInt16(UserDataRank) <= Convert.ToInt16(ObjectDataRank))
                {
                    brhandle = true;
                }
            }
            catch
            {
            }
            return brhandle;
        }
        public static Boolean GetDataRankManaAuthority(string UserDataRank, string ObjectDataRank)
        {
            Boolean brhandle = false;
            try
            {
                if (Convert.ToInt16(UserDataRank) <= Convert.ToInt16(ObjectDataRank) || UserDataRank == "0")
                {
                    brhandle = true;
                }
            }
            catch
            {
            }
            return brhandle;
        }
        #endregion
        #region//--用户功能权限处理--//
        /// <summary>
        /// 初始化用户功能权限列表
        /// </summary>
        /// <param name="strStuffID">用户ID</param>
        /// <param name="strDepID">部门ID</param>
        /// <param name="strPosID">职位ID</param>
        /// <returns>初始化否成功</returns>
        public static Boolean WriteAuthorityInXml(string strStuffID, string strDepID, string strPosID)
        {
            string strSQL = "select f_string from TS_S_T_S_FunctionList_Win where f_del=0 and (f_id in (select f_menuid from TS_S_T_S_Function_Authority_Win where f_del=0 and ((f_funcid=" + strStuffID + " and f_type=0) or (f_funcid=" + strPosID + " and f_type=1) or ((f_funcid=" + strDepID + " or f_funcid in (select f_id from TS_S_T_P_Department where f_del=0 and f_level like '%" + strDepID + "%')) and f_type=2))) or f_type=0)";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(TS_Win_Class._xml_SysSetting_Filename); //加载XML文档
            try
            {
                XmlNode xmlNode = xmlDoc.SelectSingleNode("//xml_TS_AllInOne//FunctionList");//加载节点
                xmlNode.RemoveAll();//删除权限列表
                XmlNode eltSession = xmlDoc.CreateElement("S374E6C90EF67CF21");
                eltSession.InnerText = "1";
                xmlNode.AppendChild(eltSession);
                SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
                conn.Open();
                SqlCommand comm = new SqlCommand(strSQL, conn);
                SqlDataReader read = comm.ExecuteReader();
                while (read.Read())
                {
                    eltSession = xmlDoc.CreateElement("S" + DESEncrypt.Encrypt(read["f_string"].ToString().Trim(), TS_Win_Class._xml_SysSetting_CompanyName));
                    eltSession.InnerText = "1";
                    xmlNode.AppendChild(eltSession);
                }
                xmlDoc.Save(TS_Win_Class._xml_SysSetting_Filename);
                conn.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 删除用户本地权限列表
        /// </summary>
        /// <returns>是否成功删除</returns>
        public static Boolean DelAuthorityInXml()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(TS_Win_Class._xml_SysSetting_Filename); //加载XML文档
            try
            {
                XmlNode xmlNode = xmlDoc.SelectSingleNode("//xml_TS_AllInOne//FunctionList");//加载节点
                xmlNode.RemoveAll();//删除权限列表
                XmlNode eltSession = xmlDoc.CreateElement("S374E6C90EF67CF21");
                eltSession.InnerText = "1";
                xmlNode.AppendChild(eltSession);
                xmlDoc.Save(TS_Win_Class._xml_SysSetting_Filename);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 获取用户权限授权结果
        /// </summary>
        /// <param name="strString">系统功能标示码</param>
        /// <returns>是否具有权限</returns>
        public static Boolean GetAuthorityInXmlByString(string strString,string strStuffDataRank)
        {
            if (strStuffDataRank == "0")
            {
                return true;
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(TS_Win_Class._xml_SysSetting_Filename); //加载XML文档
                try
                {
                    XmlNode xmlNode = xmlDoc.SelectSingleNode("//xml_TS_AllInOne//FunctionList//" + "S" + DESEncrypt.Encrypt(strString, TS_Win_Class._xml_SysSetting_CompanyName));//加载节点
                    if (xmlNode.InnerText.Trim() == "1")
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch
                {
                    return false;
                }
            }
        }
        #endregion
    }
    #region <<--用户登录基本信息类UserSettings
    /// <summary>
    /// 尹湘立 2012-11-15 用户登录基本信息类
    /// </summary>
    public class UserSettings
    {
        //本身
        private static UserSettings _instance = null;
        //员工标示号
        private Boolean _userLoginState = false;
        //员工标示号
        private string _guId = string.Empty;
        //登录工号
        private string _userCode = string.Empty;
        //隶属一级部门号
        private string _userDepTopID = string.Empty;
        //登录部门号
        private string _userDepIndex = string.Empty;
        //登录部门名称
        private string _userDepName = string.Empty;
        //登录职位号
        private string _userPosID = string.Empty;
        //登录职位名称
        private string _userPosName = string.Empty;
        //用户真名
        private string _userName = string.Empty;
        //登录密码
        private string _password = string.Empty;
        //登录IP
        private string _loginIp = string.Empty;
        //登录时间
        private string _loginTime = string.Empty;
        //是否连线
        private bool _isOnLine = true;
        private int f_netField = 0;
        //站段编号
        private string _userRSID = string.Empty;
        //站段名称
        private string _userRSName = string.Empty;
        //登录局ID
        private string _userRBID = string.Empty;
        //登录局名称
        private string _userRBName = string.Empty;
        //数据授权ID
        private string _userDataRangID = string.Empty;

        public UserSettings()
        {
        }

        //获取登录基本信息
        public static UserSettings Instance
        {
            get { return _instance; }
            set { _instance = (UserSettings)value; }
        }
        //员工标示号
        public Boolean UserLoginState
        {
            get { return _userLoginState; }
            set { _userLoginState = value; }
        }

        //员工标示号
        public string GuId
        {
            get { return _guId; }

            set { _guId = value; }
        }

        //登录工号
        public string UserCode
        {
            get { return _userCode; }

            set { _userCode = value; }
        }
        //隶属一级部门号
        public string UserDepTopID
        {
            get { return _userDepTopID; }

            set { _userDepTopID = value; }
        }
        //登录部门号
        public string UserDepIndex
        {
            get { return _userDepIndex; }

            set { _userDepIndex = value; }
        }

        //登录部门名称
        public string UserDepName
        {
            get { return _userDepName; }

            set { _userDepName = value; }
        }
        //登录职位号
        public string UserPosID
        {
            get { return _userPosID; }

            set { _userPosID = value; }
        }

        //登录职位名称
        public string UserPosName
        {
            get { return _userPosName; }

            set { _userPosName = value; }
        }

        //用户真名
        public string Username
        {
            get { return _userName; }

            set { _userName = value; }
        }

        //密码
        public string Password
        {
            get { return _password; }

            set { _password = value; }
        }

        //登录IP
        public string LoginIp
        {
            get { return _loginIp; }

            set { _loginIp = value; }
        }

        //登录时间
        public string LoginTime
        {
            get { return _loginTime; }

            set { _loginTime = value; }
        }

        //工作是否末连线
        public bool IsOnLine
        {
            get { return _isOnLine; }

            set { _isOnLine = value; }
        }
        public int NetField
        {
            get { return f_netField; }
            set { f_netField = value; }
        }
        //站段编号
        public string UserRSID
        {
            get { return _userRSID; }

            set { _userRSID = value; }
        }
        //站段名称
        public string UserRSName
        {
            get { return _userRSName; }

            set { _userRSName = value; }
        }
        //登录局ID
        public string UserRBID
        {
            get { return _userRBID; }

            set { _userRBID = value; }
        }
        //登录局名称
        public string UserRBName
        {
            get { return _userRBName; }

            set { _userRBName = value; }
        }
        //数据授权ID
        public string UserDataRankID
        {
            get { return _userDataRangID; }

            set { _userDataRangID = value; }
        }
    }

    #endregion
    #region <<--加密算法 DESEncrypt
    public class DESEncrypt
    {
        public DESEncrypt()
        { }
        #region =========加密===========
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="Text"></param>
        /// <returns></returns>
        public string Encrypt(string Text)
        {
            TS_Win_Class sps = new TS_Win_Class();
            return Encrypt(Text, sps.GetCompanyName());
        }

        /// <summary>
        /// 加密数据
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="sKey"></param>
        /// <returns></returns>
        public static string Encrypt(string Text, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray;
            inputByteArray = Encoding.Default.GetBytes(Text);
            des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            StringBuilder ret = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                ret.AppendFormat("{0:X2}", b);
            }
            return ret.ToString();
        }
        #endregion
        #region =======解密==================
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="Text"></param>
        /// <returns></returns>
        public string Decrypt(string Text)
        {
            TS_Win_Class sps = new TS_Win_Class();

            return Decrypt(Text, sps.GetCompanyName());
        }
        /// <summary>
        /// 解密数据
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="sKey"></param>
        /// <returns></returns>
        public static string Decrypt(string Text, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            int len;
            len = Text.Length / 2;
            byte[] inputByteArray = new byte[len];
            int x, i;
            for (x = 0; x < len; x++)
            {
                i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
                inputByteArray[x] = (byte)i;
            }
            des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            return Encoding.Default.GetString(ms.ToArray());
        }
        #endregion
        #region
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <returns></returns>
        public string md5(string str)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
        }
        #endregion
    }
    #endregion
}
#region//--SQL服务器连接--//
namespace GetSQLConnString
{
    public class GetSQLConnString
    {
        private static GetSQLConnString _CurrentSQLConnnString;
        private static String _SQLConnnString;
        public String getConnnString()
        {
            return _SQLConnnString;
        }
        public void setConnnString(String strSQLConnnString)
        {
            _SQLConnnString = strSQLConnnString;
        }

        public static GetSQLConnString getSQLConnString()
        {
            return _CurrentSQLConnnString;
        }

        public static void SetSQLConnString(GetSQLConnString user)
        {
            _CurrentSQLConnnString = user;
        }
    }
}
#endregion
#region//--本地设置参数调取--//
namespace GetLocalSetting
{
    public class GetLocalSetting
    {
        private static GetLocalSetting _CurrentLocalSetting;
        private static Boolean _Link_OK, _Link_Test_Finish, _Net_AutoDetect;
        public Boolean get_Link_OK()
        {
            return _Link_OK;
        }
        public Boolean get_Link_Test_Finish()
        {
            return _Link_Test_Finish;
        }
        public Boolean get_Net_AutoDetect()
        {
            return _Net_AutoDetect;
        }
        public void set_Net_AutoDetect(Boolean b_Net_AutoDetect)
        {
            _Net_AutoDetect = b_Net_AutoDetect;
        }
        public void set_Link_OK(Boolean b_Link_OK)
        {
            _Link_OK = b_Link_OK;
        }
        public void set_Link_Test_Finish(Boolean b_Link_Test_Finish)
        {
            _Link_Test_Finish = b_Link_Test_Finish;
        }
        public static GetLocalSetting getLocalSetting()
        {
            return _CurrentLocalSetting;
        }

        public static void SetLocalSetting(GetLocalSetting user)
        {
            _CurrentLocalSetting = user;
        }
    }
}
#endregion

